#include <iostream>
#include <math.h> 
using namespace std;


int step(int n){
	int res = 0;
	int F[1000];
	F[0] = 0;
	F[1] = 1;
	res = min(n-0,n-1);
	for(int i = 2;i < 1000;i++){
		F[i] = F[i-1] + F[i-2];
		if(res >= abs(n - F[i])){
			res = abs(n - F[i]);
		}else{
			break;
		}
	}
	return res;
}

int main(){
	int n = 0;
	cin>>n;
	int res = step(n);
	cout<<res<<endl;
	
	return 0;
} 
